
#include "base_malloclib.h"

/* 引入mmapheap */
#include <metalc/mlos/mmapheap.h>
DEF_MMAPHEAP_MLAYER(mmapheap_normal, BIT(16), SIZE_1G, SIZE_64G, 0, 0)

/* 定义buddy */
#include <metalc/mlayer/segfit_lf.h>
SAI void mark_used(void *ptr, size_t size){
	os_commit(ptr, size);
}
SAI void mark_unused(void *ptr, size_t size){
	os_decommit_lazy(ptr, size, 1);
}
DEF_SEGLF_2B_MLAYER(seglf_bin_ext, 16, HDEF_PTR_BITS, SIZE_4K, mark_used, mark_unused, mlcc_palloc, page_alloc)

#define SLAB_APDS	apdsspin

#include <metalc/mlayer/slab_lk.h>

DEF_CLS_TC(tc, 3, 15)
DEF_SLAB_MLAYER(slab, 3, 15, tc, BIT(17), 0, mlcc_palloc)

/* 定义tcache */
#include <metalc/mlayer/tcache.h>
DEF_TCACHE_MLAYER(tcache, 3, 15, tc, SIZE_4M, SIZE_2M, 2, mlcc_palloc)

/* 组合 */
COMPOSE_MLAYER(malloc_slab, mallocapi, tcache, slab, seglf_bin_ext, mmapheap_normal)

/* 定义tls */
DEF_MTLS_PTHREAD(GET_MLAYER_OBJNR(malloc_slab), 4096, mlcc_palloc, mp_coreid)


/* mlcc和mtls一定要放在第一位初始化 */
DEF_SYSINIT(malloc_perm_pool, malloc_slab, mtls)
DEF_CFLOWFIN(mtls)
DEF_CFLOWINIT(mtls, malloc_slab)
DEF_SYSFIN(__omega)